package com.yuaihen.databinding;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.yuaihen.databinding.bean.Employee;
import com.yuaihen.databinding.databinding.ActivitySimpleBinding;

/**
 * Created by Yuaihen.
 * on 2018/12/10
 */
public class SimpleActivity extends AppCompatActivity {

    Employee employee = new Employee("Zhang", "Han", false);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivitySimpleBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_simple);
        //        binding.setVariable(com.yuaihen.databinding.bean.Employee, employee);

        //数据设置 Bean
        binding.setEmployee(employee);
        binding.setPresenter(new Presenter());

    }

    /**
     * 点击事件的两种方式
     */
    public class Presenter {

        //方法引用
        public void onTextChangeListener(CharSequence s, int start, int before, int count) {
            employee.setFirstName(s.toString());
            employee.setFired(!employee.isFired.get());
            //            binding.setEmployee(employee);
        }

        public void onClick(View v) {
            Toast.makeText(SimpleActivity.this, "点击了", Toast.LENGTH_SHORT).show();
        }

        //监听器引用
        public void onClickListenerBind(Employee employee) {
            Toast.makeText(SimpleActivity.this, employee.getLastName(), Toast.LENGTH_SHORT).show();
        }
    }
}
